#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/mman.h>

#include <sys/ioctl.h>

#include <linux/videodev2.h>

typedef struct	//???????
{
	void* start;
	unsigned int length;
}buffer;

void process_image(void* start)
{
	printf("===process_image===\n");
}

int main()
{
	int fd = open("/dev/video4",O_RDWR,0);
	//获取设备信息
	struct v4l2_capability cap;
	ioctl(fd,VIDIOC_QUERYCAP,&cap);
	printf("DriverName:%s\nCard Name:%s\nBus info:%s\nDriverVersion:%u.%u.%u\n",cap.driver,cap.card,cap.bus_info,(cap.version>>16)&0xff,(cap.version>>8)&0xff,cap.version&0xff);
	//显示所有支持的帧格式
	struct v4l2_fmtdesc fmtdesc;
	fmtdesc.index=0;
	fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	printf("Support format:\n");
	while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
	{
		printf("\t%d.%s\n",fmtdesc.index+1,fmtdesc.description);
		fmtdesc.index++;
	}
	//显示当前帧的相关信息
	struct v4l2_format fmt;
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	ioctl(fd,VIDIOC_G_FMT,&fmt);
	printf("Currentdata format information:\n\twidth:%d\n\theight:%d\n",fmt.fmt.pix.width,fmt.fmt.pix.height);
	/*struct v4l2_fmtdesc fmtdesc;
	fmtdesc.index = 0;
	fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1)
	{
		if(fmtdesc.pixelformat& fmt.fmt.pix.pixelformat)
		{
			printf("\tformat:%s\n",fmtdesc.description);
			break;
		}
		fmtdesc.index++;
	}
	*/
}
